package net.zjitc.controller;

import net.zjitc.pojo.UUser;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.net.http.HttpResponse;

@Controller
public class AjaxController {
    //检测用户名是否存在？username
    @PostMapping(value = "/checkname",produces = "text/html;charset=UTF-8")
    @ResponseBody //返回不是jsp,返回的是响应体
    public String checkUsername(String username, HttpServletResponse response){
        //response.setHeader("Charset","UTF-8");
        //response.setContentType("text/html;charset=UTF-8");
        if("zhangsan".equals(username)){
            return "此用户名已经被使用";
        }else {
            return "此用户名可使用";
        }
    }
    @PostMapping(value = "/checkname2",produces = "text/html;charset=UTF-8")
    @ResponseBody //返回不是jsp,返回的是响应体
   // @RequestBody json格式转换
    public String checkUsername2(@RequestBody UUser user, HttpServletResponse response){
        //response.setHeader("Charset","UTF-8");
        //response.setContentType("text/html;charset=UTF-8");
        if("zhangsan".equals(user.getUsername())){
            return "此用户名已经被使用";
        }else {
            return "此用户名可使用";
        }
    }
}
